{% extends "configuration/left_menu.html" %}

{% block right_content %}

<div id="right_menu">

   <div class="row">
        <div class="col-md-2">
            <h3><strong>添加配置元数据</strong></h3>
        </div>
        <div class="col-md-10">
            <div class="alert-msg"></div>
        </div>

    </div>
    <hr/>
	<div class="column-row">

           <!-- <div class="form-inline"> -->
           <div class="column-text">
                <label class="position_center" for="svn_path">svn仓库路径:</label>
           </div>

           <div class="column-body-single-input-text">
           		<input id="svn_path" type="text" class="form-control" placeholder="请输入模块配置的svn仓库路径" />
           </div>
    </div><br>

    <div class="column-row">

           <div class="column-text">
                <label class="position_center" for="manage_path" >管理节点路径:</label>
           </div>

           <div class="column-body-single-input-text">
           		  <input id="manage_path" type="text" class="form-control" placeholder="管理节点路径" />
           </div>
    </div><br>

	<div class="column-row">

        <!-- <div class="form-inline"> -->
    <div class="column-text">
          <label class="position_center" for="">请选择类型:</label>
    </div>
    <div class="column-body-single-input-text">
     		<select id="category" class="form-control">
              {% for category in categorys %}
           			  <option value="{{ category.id }}">{{ category.category_name }}</option>
              {% endfor %}
     		</select>
    </div>
  </div><br>

  <div class="column-row">

    	<div class="col-md-2">
    		  <button type="submit" id="add_config_meta" class="btn btn-success" >提交</button>
    	</div>

    	<div class="col-md-2">
    		  <button type="reset" id="reset_meta" class="btn btn-danger">重置</button>
    	</div>

  </div>
</div>

<script type="text/javascript">

	$('#add_config_meta').click(function() {
		// some code for add config.
    var svn_path = $('#svn_path').val();
    var manage_path = $('#manage_path').val();
    var category_id = $('#category option:selected').val();

    if(svn_path == '') {
        alert_msg('warning', 'svn_path不能为空!');
        return
    }

    if(manage_path == '') {
       alert_msg('warning', 'manage_path不能为空!');
       return
    }

    var url = "{% url 'configuration:addConfigMeta' %}";

    var postdata = {
        svn_path : svn_path,
        manage_path : manage_path,
        category : category_id
    };

    var ret_data = $.ajax({

            url : url,
            type : "POST",
            data : postdata,
            async : false,
            cache : false
    });

    if(ret_data.status == 200) {
        app_res_status = ret_data.responseJSON.status;
        message = ret_data.responseJSON.message;
        if(app_res_status == 1) {
            alert_msg('success', message);
            setTimeout(function() {
              window.location.href="{% url 'configuration:showListForm' %}";
            }, 2500);
        } else {
            alert_msg('danger', message);
        }
    } else {
        alert_msg('danger', "服务器错误!");
    }
	});

  $('#reset_meta').click(function() {
        window.location.href="{% url 'configuration:showAddForm' %}";
  });

</script>

{% endblock %}

